<template>
	<view class="password">
		<view>旧密码</view>
		<input class="editInput" v-model="formData.password" placeholder="输入新的密码" placeholder-class="placeholder" />
	</view>
	<view class="password">
		<view>新密码</view>
		<input class="editInput" v-model="formData.newPassword" placeholder="输入新的密码" placeholder-class="placeholder" />
	</view>
	<view class="add_buttom" @click="addFn">提交</view>
</template>

<script setup>
	import { computed ,ref,reactive,toRefs,onMounted} from 'vue';
	import { onLoad,onShow, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
	import sheep from '@/sheep';
	
	const formData=ref({
		phone:'',
		password:'',
		newPassword:''
	})
	const form=ref({
		phone:'',
		password:'',
	})
	onLoad(()=>{
		formData.value.phone=sheep.$store('user').userInfo.phone
		console.log(formData.value.phone);
		form.value.phone=sheep.$store('user').userInfo.phone
	})
	
	// updateLogin
	const addFn=()=>{
	    form.value.password=formData.value.newPassword
		sheep.$api.login.updateLogin(formData.value).then(res=>{
			console.log(res);
			if(res.msg=="修改成功"){
				uni.showToast({
					title:"修改成功！",
					icon:'success'
				})
				uni.removeStorageSync("login_account")
				
				setTimeout(()=>{
					uni.setStorageSync("login_account",form.value)
					uni.removeStorageSync('token')
					uni.reLaunch({
						url:"/pages/index/loginpassword"
					})
					
				},500)
			}else if(res.msg=="旧密码不正确"){
				uni.showToast({
					title:"旧密码错误",
					icon:'error'
				})
				
			}
		})
	}
</script>
<style lang="scss" scoped>
	page{
		padding:30rpx;
	}
	.password{
		display: flex;
		align-items: center;
		background-color: #fff;
		padding:20rpx;
	}
	.editInput{
		margin-left: 10rpx;
	}
	.placeholder{
		font-size: 28rpx;
	}
	.add_buttom{
		margin: 30rpx 0;
		padding: 20rpx;
		color: #fff;
		text-align: center;
		border-radius: 15rpx;
		background-image: linear-gradient(90deg,#f892a9,#f8a3b6,#f8b7c7,#f8c9d5,#f8d2db);
	}
</style>